package com.ticket.sass.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ticket.sass.admin.mapper.PriceSchemeWeekMapper;
import com.ticket.sass.admin.service.BaseService;
import com.ticket.sass.common.entity.tenant.PriceSchemeWeekEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ywb
 * @since 2024-04-09
 */
@Service
public class PriceSchemeWeekServiceImpl extends ServiceImpl<PriceSchemeWeekMapper, PriceSchemeWeekEntity> implements BaseService<PriceSchemeWeekEntity> {
    public Map<Long, List<PriceSchemeWeekEntity>> listWeekEntitiesByPriceSchemeIds(List<Long> priceSchemeIds) {
        if (priceSchemeIds.isEmpty()) {
            return new HashMap<>();
        }
        
        Map<Long, List<PriceSchemeWeekEntity>> resultMap = new HashMap<>();
        
        // 一次性查询所有价格方案对应的周实体列表
        List<PriceSchemeWeekEntity> weekEntities = this.baseMapper.selectList(new QueryWrapper<PriceSchemeWeekEntity>().in("price_scheme_id", priceSchemeIds));
        
        // 构建结果映射
        for (PriceSchemeWeekEntity weekEntity : weekEntities) {
            Long priceSchemeId = weekEntity.getPriceSchemeId();
            if (!resultMap.containsKey(priceSchemeId)) {
                resultMap.put(priceSchemeId, new ArrayList<>());
            }
            resultMap.get(priceSchemeId).add(weekEntity);
        }
        return resultMap;
    }
}
